//
//  ChangePswViewController.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/9.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "ChangePswViewController.h"
#import "ForgetPswViewController.h"
#import "BaseTextField.h"
#import "CYXBaseRequest.h"

@interface ChangePswViewController ()
@property (weak, nonatomic) IBOutlet UILabel *hid;
@property (weak, nonatomic) IBOutlet BaseTextField *oPswInput;
@property (weak, nonatomic) IBOutlet BaseTextField *nPswInput;
@property (weak, nonatomic) IBOutlet BaseTextField *ncPswInput;

@end

@implementation ChangePswViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setRightNavItem:LCLocalString(@"psw_wjymm") font:[UIFont boldSystemFontOfSize:12] color:nil icon:nil];
    // Do any additional setup after loading the view from its nib.
}

- (void)setupUI{
    [super setupUI];
    self.title = LCLocalString(@"psw_xgmm");
    self.oPswInput.placeholder = LCLocalString(@"plh_qsrymm");
    self.oPswInput.placeholderColor = PlhColor;
    self.nPswInput.placeholder = LCLocalString(@"plh_qsrxmm");
    self.nPswInput.placeholderColor = PlhColor;
    self.ncPswInput.placeholder = LCLocalString(@"psw_zcsrxmm");
    self.ncPswInput.placeholderColor = PlhColor;
    
    UserInfoModel *user = kAppDelegate.curUser;
    self.hid.text = user.hid;
}

- (void)rightNavItemClick:(id)sender{
    ForgetPswViewController *vc = LoadVCFormXib(ForgetPswViewController);
    [self.navigationController pushViewController:vc animated:YES];
}

- (BOOL)checkInpt{
    if (!self.oPswInput.text.length) {
        LCInfoHUD(self.oPswInput.placeholder, 1);
        return NO;
    }
    if (!self.nPswInput.text.length) {
        LCInfoHUD(self.nPswInput.placeholder, 1);
        return NO;
    }
    if (!self.ncPswInput.text.length) {
        LCInfoHUD(self.ncPswInput.placeholder, 1);
        return NO;
    }
    if (self.nPswInput.text.length < 8 || self.nPswInput.text.length > 20) {
        LCInfoHUD(LCLocalString(@"mmcwts"), 1);
        return NO;
    }
    
    if (![self.nPswInput.text isEqualToString:self.ncPswInput.text]) {
        LCInfoHUD(LCLocalString(@"lcmmbt"), 1);
        return NO;
    }
    
    
    return YES;
}

- (IBAction)doneAction:(id)sender {
    if(![self checkInpt]) return;
    
    NSDictionary *param = @{@"newPassword":self.nPswInput.text,@"password":self.oPswInput.text};

    [CYXBaseRequest postWithUrl:API_modifyPassword param:param resultClass:nil success:^(id res) {
        if ([res isEqual: RequestErrorCode]) {
            
        }else{
            LCInfoHUD(@"修改成功", 1);
            [self.navigationController popViewControllerAnimated:YES];
        }
//        LCInfoHUD(@"修改成功", 1);
//        [self.navigationController popViewControllerAnimated:YES];
        
        CYXLog(@"%@",res)
    } failure:^(NSError *error) {
        CYXLog(@"%@",error)
    }];
    
}


@end
